package com.csdj.s3project.utils;

import java.util.Random;
import java.util.UUID;

public class RandomUtil {

    /**
     * 生成token用于登录验证
     * @return
     */
    public static String genToken(){
        String s = UUID.randomUUID().toString();
        return s.replaceAll("-","");
    }

    /**
     * 随机生成六位数字验证码
     * @return
     */
    public static String getCheckCode() {
//        String ZiMu = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGJKLZXCVBNM1234567890";
        String ZiMu = "1234567890";
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            int index = random.nextInt(ZiMu.length());
            char c = ZiMu.charAt(index);
            result += c;
        }
        return result;
    }

    /**
     * 随机生成八位邀请码,英文字母+数字
     * @return
     */
    public static String getInvitationCode() {
        String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 8; i++) {
            int index = random.nextInt(alphabet.length());
            char c = alphabet.charAt(index);
            result += c;
        }
        return result;
    }


    public static String getRandomPosition(int count){
        //碎片位置字符串
        StringBuffer piecesPosition = new StringBuffer();
        //随机生成碎片位置值
        Random random = new Random();
        //单个碎片位置值
        String piece = "";
        if(count > 1){
            for(int i = 0;i<count; i++){
                piece = String.valueOf(random.nextInt(9)+1);
                piecesPosition.append(piece+",");
            }
            return piecesPosition.toString();
        }
        //单抽
        piece = (random.nextInt(9)+1)+",";
        return piece;
    }



}
